package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;



    /**
     * 分页查询供应商信息
     * @param page
     * @param rows
     * @return
     */
    @Override
    public Map<String, Object> getSupplier(Integer page, Integer rows,String supplierName) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(page,rows);
        Page<Supplier> supplierPage = supplierDao.selectSupplier(supplierName);
        map.put("total",supplierPage.getTotal());
        map.put("rows",supplierPage.getResult());
        return map;


    }

    /**
     * 添加
     * @param supplier
     */
    @Override
    public void saveSupplier(Supplier supplier) {
        supplierDao.insertSupplier(supplier);
    }

    @Override
    public void updateSupplier(Supplier supplier) {

        supplierDao.updateSupplier(supplier);
    }

    @Override
    public void deleteSupplier(String[] supplierId) {
        supplierDao.deleteSupplier(supplierId);
    }


}
